<template>
  <q-page class="cc-admin row">
    <div class="col-6 cc-view-catalog">
      <q-table
        flat
        color="primary"
        class="cross_table"
        separator="cell"
        :columns="columns"
        :data="list"
        row-key="id"
        :rows-per-page-options="[10, 20, 50, 100]"
        :pagination.sync="pagination"
        @request="query"
      >
        <template v-slot:top="table">
          <div class="row no-wrap full-width">
            <q-input
              clearable
              outlined
              dense
              placeholder="请输入关键字搜索"
              class="on-left"
              @input="query"
              debounce="500"
              v-model="key"
            >
              <template #append>
                <q-btn
                  flat
                  round
                  icon="search"
                  color="primary"
                  @click="query"
                  :loading="loading"
                >
                  <q-tooltip>搜索</q-tooltip>
                </q-btn>
              </template>
            </q-input>
            <q-space />
            <table-top-btns
              label="字典管理"
              modelName="dict"
              :showAdd="true"
              :showImport="false"
              :showExport="false"
              :showDeleteBatch="false"
              :showGroup="false"
              :table="table"
              :selected="selected"
              :importing="importing"
              :exporting="exporting"
              :importExcelUrlFull="importExcelUrlFull"
              :columns="columns"
              @groupChange="groupChange"
              @add="add"
              @importExcel="importExcel"
              @exportExcel="exportExcel"
              @showConfirm="showConfirm"
            />
          </div>
        </template>
        <template v-slot:body="props">
          <q-tr
            :props="props"
            :class="[
              'cursor-pointer',
              selected.length === 1 && selected[0].id === props.row.id
                ? 'bg-cyan-3'
                : '',
            ]"
            @click.native="selectDict(props.row)"
          >
            <q-td key="index" :props="props">{{ props.row.index }}</q-td>
            <q-td key="dictName" :props="props">{{ props.row.dictName }}</q-td>
            <q-td key="dictCode" :props="props">{{ props.row.dictCode }}</q-td>
            <q-td key="description" :props="props">{{
              props.row.description
            }}</q-td>
            <q-td key="opt" :props="props" :auto-width="true">
            <cc-btn label="编辑" color="primary" icon="edit" @click="edit(props.row)"> <q-tooltip>编辑</q-tooltip></cc-btn>
              <btn-del label="数据字典" @confirm="del(props.row)" />
            </q-td>
          </q-tr>
        </template>
      </q-table>
    </div>
    <div class="col">
      <item :selectedDictArray="selected" />
    </div>
    <cc-dialog ref="dialog" :title="`${editType}数据字典`" @submit="submit">
      <div class="col-12">
        <h5><q-icon name="star" color="red" />字典名称：</h5>
        <q-input
          outlined
          dense
          v-model="form.dictName"
          type="text"
          :rules="[requiredTest]"
        />
      </div>
      <div class="col-12">
        <h5><q-icon name="star" color="red" />字典编码：</h5>
        <q-input
          outlined
          dense
          v-model="form.dictCode"
          type="text"
          :rules="[requiredTest]"
        />
      </div>
      <div class="col-12">
        <h5>描述：</h5>
        <q-input
          outlined
          dense
          v-model="form.description"
          type="textarea"
          :rules="[]"
        />
      </div>
    </cc-dialog>
    <cc-loading :loading="loading"/>
  </q-page>
</template>

<script>
import { requiredTest, letterTest } from 'boot/inputTest';
import { IndexMixin } from 'boot/mixins';
import item from './item';

export default {
  name: 'SysDict',
  mixins: [IndexMixin],
  components: {
    item,
  },
  data() {
    return {
      splitterModel: 50,
      columns: [
        {
          name: 'index',
          align: 'center',
          label: '序号',
          field: 'index',
          headerClasses: 'cc-table-index',
        },
        {
          name: 'dictName',
          align: 'left',
          label: '字典名称',
          field: 'dictName',
        },
        {
          name: 'dictCode',
          align: 'left',
          label: '字典编码',
          field: 'dictCode',
        },
        {
          name: 'description',
          align: 'left',
          label: '描述',
          field: 'description',
        },
        {
          name: 'opt',
          align: 'center',
          label: '操作',
          field: 'opt',
        },
      ],
      url: {
        list: '/sys/dict/list',
        add: '/sys/dict/add',
        edit: '/sys/dict/edit',
        delete: '/sys/dict/delete',
        deleteBatch: '/sys/dict/deleteBatch',
        exportXlsUrl: '/sys/dict/exportXls',
        importExcelUrl: '/sys/dict/importExcel',
      },
    };
  },
  methods: {
    requiredTest,
    letterTest,
    selectDict(row) {
      this.selected.pop();
      this.selected.push(row);
    },
    delAfter() {
      this.selected.pop();
    },
  },
  computed: {
  },
  mounted() {
    this.query();
  },
};
</script>

<style lang="stylus"></style>
